<?php


namespace app\job;

use app\home\service\CardSettlementService;
use think\facade\Log;
use think\queue\Job;

/**
 * 开牌后用户结算
 * Class UserSettleTaskJob
 * @package app\job
 */
class UserSettleTaskJob
{
    public function fire(Job $job, $data = null)
    {
        $info = $data;
        #逻辑执行
        //Db::name('test')->insert(['aaaa'=>date('Y-m-d H:i:s'),'bbbb'=>rand(10,100),'cccc'=>rand(10,100)]);
        $luzhu_id = $data['luzhu_id'];
        unset($data['luzhu_id']);
        $card_service = new CardSettlementService();
        $res = $card_service->user_settlement($luzhu_id,$data);
        if ($res){
            $job->delete();
            return;
        }
        #逻辑执行结束
        if ($job->attempts() > 3) {
            Log::info('用户结算执行失败:'.json_encode($info));
            $job->delete();
            return;
            //通过这个方法可以检查这个任务已经重试了几次了
        }
        //如果任务执行成功后 记得删除任务，不然这个任务会重复执行，直到达到最大重试次数后失败后，执行failed方法
        // 也可以重新发布这个任务
        //$job->release(0); //$delay为延迟时间
    }
}